package action;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import entity.Student;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import service.impl.StudentServiceImpl;

/**
 * Servlet implementation class QueryStudentAction
 */
@WebServlet("/queryStudentAction")
public class QueryStudentAction extends HttpServlet {
	private static final long serialVersionUID = 1L;
	
	private StudentServiceImpl studentService = new StudentServiceImpl();
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public QueryStudentAction() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		response.setCharacterEncoding("UTF-8");
		List<Student> students = studentService.queryStudents();
		JSONArray data = JSONArray.fromObject(students);
		response.getWriter().append(data.toString());
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
